<!DOCTYPE HTML>
<html>
<head>
    <title>订单添加页</title>
    <link href="css/addOrder.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="css/foot.css"/>
    <link rel="stylesheet" href="css/head.css"/>
    <meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
    <script type="text/javascript" src="js/base-v1.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/jquery-1.2.6.min.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/cookie.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/common.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/jquery.cookie.js" charset="utf-8"></script>
    <script type="text/javascript" src="s/base-2011.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/jquery.min.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/jquery-extend.js"></script>
    <script type="text/javascript" src="js/logout.js"></script>
    <script type="text/javascript" src="js/lib-v1.js" charset="utf-8"></script>
    <meta charset="UTF-8">
</head>
<body>
<script type="text/javascript">
    $(function(){
        // alert("好啊1");
        var userId="";
        var _ticket = $.cookie("EM_TICKET");
        if(!_ticket){
            window.location.href="login.html";
            return ;
        }
        //当dataType类型为jsonp时，jQuery就会自动在请求链接上增加一个callback的参数
        $.ajax({
            url : "http://www.easymall.com/user/query/" + _ticket,
            dataType : "json",
            type : "GET",
            success : function(data){

                if(data.status == 200){
                    var _data = JSON.parse(data.data);//jackson
                    if(_data==null){
                        alert("啥也别说了，你的用户超时了,赶紧查查redis还有数据没有");
                        window.location.href="./login.html";
                        return;}
                    var html =_data.userName+"，欢迎来到京淘！<a href=\"javascript:void(0)\" class=\"link-logout\" onclick='logout()'>[退出]</a>  \|<a href=\"http://www.easymall.com/manage.html\" class=\"link-logout\">[后台]</a>";
                    userId=_data.userId;
                    $("#loginbar").html(html);
                    query(userId);
                }else{
                    alert("咋了兄弟，购物车没东西自己心里没数吗，赶紧购物去");
                }
            },
            error : function(){
                alert('index error.');
            }
        });
    });
    function query(userId){
        $.ajax({
            url:"http://www.easymall.com/cart/query?userId="+userId,
            dataType:"json",
            type:"GET",
            success:function(data){
                if(data.length>0){
                    var money=0;
                    $.each(data,function(index, cart){
                        var productId=cart.productId;
                        var productName=cart.productName;
                        var productPrice=cart.productPrice;
                        var productImage=cart.productImage;
                        var num=cart.num;
                        var prodHtml="product-info.html?productId="+productId;
                        var inputId="hid_"+productId;
                        var itemMoney=productPrice*num;
                        money=money+itemMoney;
                        $("#myorderTable").append("<tr><input type=\"hidden\" name=\"orderItems["+index+"].productImage\" value=\""+productImage+"\"/><td><img src=\""+productImage+"\" width=\"90\" height=\"90\" /></td><input type=\"hidden\" name=\"orderItems["+index+"].productId\" value=\""+productId+"\"/><td>"+productName+"</td><input type=\"hidden\" name=\"orderItems["+index+"].productName\" value=\""+productName+"\"/><td>"+productPrice+"元</td><input type=\"hidden\" name=\"orderItems["+index+"].productPrice\" value=\""+productPrice+"\"/><td>"+num+"件</td><input type=\"hidden\" name=\"orderItems["+index+"].num\" value=\""+num+"\"/><td>"+itemMoney+"元</td>");
                    })
                    $("#myorderTable").append("<input type=\"hidden\" name=\"orderMoney\" value=\""+money+"\"/>");
                    document.getElementById("total_money").innerText="总价:"+money+"元";
                    $("#myorderTable").append("<input type=\"hidden\" name=\"userId\" value=\""+userId+"\"/>");
                }else{
                    alert("你是不是没登陆啊");
                }
            }
        });
    }
    function submitForm(){
        alert($("#addOrderForm").serialize());
        $.post("/order/save",$("#addOrderForm").serialize(), function(data){
            if(data.status == 200){
                alert("新增订单成功,转向订单查询页面");
                window.location.href="./myorder.html";
            }else if(data.status==201){
                //对不起失败
                alert("新增订单失败,查看失败原因");
            }
        });
    }
    function search(a){
        var query=document.getElementById(a).value;
        //alert(query);
        window.location.href="./search.html?query="+query;

    }
</script>
<div id="common_head">
    <div id="line1">
        <div id="content">
            <li class="fore1" id="loginbar" clstag="homepage|keycount|home2013|01b">
                <span id="head_span"\\\x><a href="login.html">登录</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="regist.html">注册</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="manage.html">后台</a></span>

            </li>
        </div>
    </div>
    <div id="line2">
        <img id="logo" src="img/head/logo.jpg"/>
        <input type="text" value="" accesskey="s" id="key" autocomplete="off" onkeydown="javascript:if(event.keyCode==13) search('key');"/>
        <input type="button" value="搜 索" onclick="search('key')"/>
        <span id="goto">
			<a id="goto_order" href="./myorder.html">我的订单</a>
			<a id="goto_cart" href="./mycart.html">我的购物车</a>
		</span>
        <img id="erwm" src="img/head/qr.jpg"/>
    </div>
    <div id="line3">
        <div id="content">
            <ul>
                <li><a href="#">首页</a></li>
                <li><a href="./product-list.html?page=1&rows=5">全部商品</a></li>
                <li><a href="/web/sekill/list">秒杀商品</a></li>
                <li><a href="#">电脑平板</a></li>
                <li><a href="#">家用电器</a></li>
                <li><a href="#">汽车用品</a></li>
                <li><a href="#">食品饮料</a></li>
                <li><a href="#">图书杂志</a></li>
                <li><a href="#">服装服饰</a></li>
                <li><a href="#">理财产品</a></li>
            </ul>
        </div>
    </div>
</div>
<div class="warp">
    <form id="addOrderForm" name="form1" method="post">
        <h3>增加订单</h3>
        <div id="forminfo">
            <span class="lf">收货地址：</span> <label for="textarea"></label>
            <textarea name="orderReceiverinfo" id="textarea" cols="45" rows="5"></textarea>
            <br> 支付方式：<input name="" type="radio" value="" checked="checked">&nbsp;在线支付
        </div>
        <table id="myorderTable" width="1200" height="80" border="1" cellpadding="0" cellspacing="0" bordercolor="#d8d8d8">
            <tr>
                <th width="276">商品图片</th>
                <th width="247">商品名称</th>
                <th width="231">商品单价</th>
                <th width="214">购买数量</th>
                <th width="232">小计</th>
            </tr>


        </table>
        <div class="Order_price" id="total_money"></div>
        <div class="add_orderbox">
            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()"><img src="./img/orderList/addOrder.png" width="120" height="38"></a>
        </div>
    </form>
</div>
<div id="common_foot">
    <p>
        Copyright © 2011-2015 达内软件技术有限公司 版权所有 保留一切权利 苏B2-20130048号 | 京ICP备09062682号-9
        <br>
        网络文化经营许可证苏网文[2012]0401-019号
    </p>
</div>
</body>
</html>